import { makeAutoObservable } from 'mobx'
import variable from './variable'

export interface VideoInfo {
  id: string
  like: number
  meLike: boolean
  collect: number
  share: number
  comment: number
  author: string
  description: string
  authorCover: any
  videoCover: string
  videoSource: string
  title: string
  isFirstShow: boolean
}
const authorCover = require('../assets/images/avatar.jpg')
class VideoSwiper {
  videoList: VideoInfo[] = [
    {
      id: '0',
      like: 0,
      meLike: false,
      isFirstShow: true,
      collect: 0,
      share: 0,
      comment: 0,
      author: 'Admin-min',
      authorCover: authorCover,
      videoCover: '',
      videoSource: variable.resourceURL + 'videoSource/video1.mp4',
      description:
        '这是一段描述描述。。。这是一段描述描述。。。这是一段描述描述。。。\n这是一段描述描述。。。这是一段描述描述。。。这是一段描述描述。。。这是一段描述描述。。。这是一段描述描述。。。\n这是一段描述描述。。。这是一段描述描述。。。',
      title: '祝你晚上好，中午好，早上好',
    },
    {
      id: '1',
      like: 10,
      meLike: false,
      isFirstShow: true,
      collect: 0,
      share: 0,
      comment: 5,
      author: '猫头鹰工作坊',
      authorCover: authorCover,
      videoCover: '',
      videoSource: variable.resourceURL + 'videoSource/video2.mp4',
      description:
        '这是一段描述描述2。。。这是一段描述描述2。。。这是一段描述描述2。。。\n这是一段描述描述2。。。这是一段描述描述。2。。这是一段描述描述。。。这是一段描述描述。。。这是一段描述描述。。。\n这是一段描述描述。。。这是一段描述描述。。。',
      title: '祝你早上好，中午好，晚上好',
    },
  ]
  currentVideoId = '0' // 当前显示的video
  showCommentPage = false // 是否显示视频评论
  constructor() {
    makeAutoObservable(this)
  }
  get currentVideo() {
    return this.videoList.find(item => item.id === this.currentVideoId)
  }
  getVideoById(id: string) {
    if (!id) return undefined
    return this.videoList.find(item => item.id === id)
  }
  setVideoLike(id: string) {
    const info = this.getVideoById(id)
    if (!info) return
    if (this.currentVideo) {
      if (info.meLike) {
        info.like--
        info.meLike = false
      } else {
        info.like++
        info.meLike = true
      }
    }
  }
  // 不是第一次显示video
  setVideoUnFirst(id: string) {
    const info = this.getVideoById(id)
    if (!info) return
    info.isFirstShow = false
  }
  setShowCommentPage(val: boolean) {
    this.showCommentPage = val
  }
  setCurrentVideoId(val: string) {
    this.currentVideoId = val
  }
  addVideoItem() {
    const info: VideoInfo = {
      id: this.videoList.length + '',
      like: parseInt(Math.random() * 20 + '', 10),
      meLike: false,
      isFirstShow: true,
      collect: 0,
      share: 0,
      comment: parseInt(Math.random() * 10 + '', 10),
      author: '追加-🌟' + this.videoList.length,
      authorCover: authorCover,
      videoCover: '',
      videoSource: variable.resourceURL + 'videoSource/video1.mp4',
      description: '这是自动加载的视频，描述',
      title: '这是自动加载的视频，标题',
    }
    this.videoList.push(info)
  }
}
const videoSwiperStore = new VideoSwiper()
export default videoSwiperStore
